<template>
	<view class="login-content">
		<view class="content-box">
			<view class="logo">
				<image src="../../static/images/logo.png"></image>
				<!-- <view class="t0">缘定缘分</view> -->
				<view class="t1">让爱如初 情深缘厚</view>
			</view>
			<view class="form-box">
				<view class="form-item">
					<h3>账号</h3>
					<uv-input type="text" border="none" :maxlength="11" placeholder="请输入手机号"
						v-model="user.account"></uv-input>
				</view>
				<view class="form-item">
					<h3>密码</h3>
					<uv-input type="password" border="none" :maxlength="11" placeholder="请输入密码"
						v-model="user.password"></uv-input>
				</view>
			</view>
			<view class="btn-box">
				<view class="agree-text">
					<image src="../../static/images/login/beifen1.png" v-if="isAgree" @click="isAgree = false">
					</image>
					<image src="../../static/images/login/beifen3.png" v-if="!isAgree" @click="isAgree = true">
					</image>
					<view class="agree-tit">
						我已阅读并同意
						<text @click="isshowAgree = true">《缘定缘分商户协议》</text>
					</view>
				</view>
				<button class="btn" @click="goLogin">立即登录</button>
			</view>
		</view>
		<view class="agree-dialog" v-if="isshowAgree">
			<view class="agree-box">
				<view class="t0">
					《缘定缘分商户协议》
					<view class="close" @click="isshowAgree = false">
						<image src="../../static/images/login/beifen2.png"></image>
					</view>
				</view>
				<view class="content">
					<view class="t1">
						<uv-parse :content="agreementArticle"></uv-parse>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import api from '../../api/index.js';
	export default {
		data() {
			return {
				isshowAgree: false,
				isAgree: false,
				agreementArticle:null,
				mobileUser: { // 手机登录 
					mobile: '', // 15515515515
					captcha: ''
				},
				user: {
					account: '', //15515515515
					password: '' //111111
				}
			};
		},
		onLoad() {
			this.getAgreementArticle()
		},
		methods: {
			goLogin() {
				if (!this.isAgree) {
					return uni.showToast({
						icon: 'none',
						title: '请先阅读协议！'
					});
				}
				if (!(this.user.account && this.user.password)) {
					return uni.showToast({
						icon: 'none',
						title: '用户名或密码不能为空！'
					})
				}
				api.login(this.user).then(res => {
					let token = res.data.userinfo.token;
					this.$store.commit('saveToken', token)
					this.getUserInfo()

				});
			},
			getAgreementArticle(){
				api.getAgreementArticle({
					biaoshi:'agrnt_user_agreement'
				}).then(res => {
					this.agreementArticle = res.data.content
				});
			},
			getUserInfo() {
				api.getUserInfo().then(res => {
					let info = res.data.userinfo;
					if (info) {
						uni.setStorageSync('userinfo', info);
						this.$store.commit('saveUserInfo', info)
					}
					uni.switchTab({
						url: '/pages/home/index'
					});
				});
			},
		}
	};
</script>

<style lang="scss" scoped>
	.login-content {
		background: url('../../static/images/login/login-top.png') no-repeat;
		background-size: 100% 319rpx;
		padding-top: 280rpx;
		// height: 100vh;
		position: relative;

		.content-box {
			background: url('../../static/images/login/login-form-bg.png') no-repeat;
			background-size: 100% 100%;
			margin: 0 28rpx 0;
			padding: 32rpx 40rpx;

			.logo {
				uni-image {
					width: 160rpx;
					height: 160rpx;
				}

				text-align: center;

				.t0 {
					margin-top: 20rpx;
					font-size: 54rpx;
					line-height: 54rpx;
					font-style: normal;
					font-weight: 550;
				}

				.t1 {
					margin-top: 20rpx;
					font-weight: 400;
					font-size: 26rpx;
					line-height: 32rpx;
					font-style: normal;
				}
			}

			.form-box {
				margin-top: 60rpx;

				.form-item {
					margin-bottom: 36rpx;

					h3 {
						font-family: SourceHanSansSC, SourceHanSansSC;
						font-weight: bold;
						font-size: 34rpx;
						color: #000000;
						line-height: 50rpx;
						font-style: normal;
						margin-bottom: 12rpx;
					}

					.uv-input {
						background: #f7f7f7;
						border-radius: 12rpx;
						font-weight: 400;
						font-size: 28rpx;
						// color: #bdbdbd;
						height: 88rpx;
						font-style: normal;
						padding: 0 28rpx;
					}
				}
			}

			.btn-box {
				.btn {
					// width: 436rpx;
					height: 88rpx;
					background: linear-gradient(311deg, #93a4fb 0%, #2f9afe 100%);
					box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(20, 135, 255, 0.4);
					border-radius: 44rpx;
					font-weight: 500;
					font-size: 34rpx;
					color: #ffffff;
					line-height: 88rpx;
					text-align: center;
					font-style: normal;
				}

				.agree-text {
					display: flex;
					align-items: center;
					justify-content: start;
					margin: 60rpx auto 20rpx;

					uni-image {
						width: 40rpx;
						height: 40rpx;
					}

					.agree-tit {
						margin-left: 20rpx;
						font-weight: 400;
						font-size: 28rpx;
						color: #999999;
						line-height: 40rpx;
						text-align: right;
						font-style: normal;

						uni-text {
							color: #49a1fd;
						}
					}
				}
			}
		}

		.agree-dialog {
			background: rgba(0, 0, 0, 0.6);
			position: fixed;
			top: 0;
			bottom: 0;
			left: 0;
			right: 0;
			overflow: auto;

			.agree-box {
				background: url('../../static/images/login/login-form-bg.png') no-repeat;
				background-size: 100% 100%;
				padding: 40rpx 30rpx;
				margin: 200rpx 40rpx 88rpx;

				.t0 {
					font-weight: 500;
					font-size: 34rpx;
					color: #000000;
					line-height: 48rpx;
					text-align: center;
					font-style: normal;
					position: relative;
					padding-bottom: 20rpx;

					.close {
						position: absolute;
						right: 0;
						top: 0;
						cursor: pointer;

						uni-image {
							width: 26rpx;
							height: 26rpx;
						}
					}
				}

				.content {
					max-height: 60vh;
					overflow-y: scroll;

					.t1 {
						font-weight: 400;
						font-size: 28rpx;
						color: #444444;
						line-height: 50rpx;
						text-align: left;
						font-style: normal;
					}
				}

			}
		}
	}
</style>